﻿#include "SEAShellWapper.h"
#include "FITK_Kernel/FITKAppFramework/FITKMessage.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsPhysics.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsMaterial.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsShellPhysicsProp.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsNCT.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsSpectraManager.h"
#include "OperatorsInterface/GraphEventOperator.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"

SEAShell* SEAShellWapper::new_SEAShell()
{
    SEAShell* shell = new SEAShell;
    this->initShell(shell);
    return shell;
}

void SEAShellWapper::delete_SEAShell(SEAShell* obj)
{
    if (obj) delete obj;
    //渲染层显示数据
    EventOper::GraphEventOperator* graphOper = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("GraphPreprocess");
    if (graphOper == nullptr)return;
    graphOper->updateSEASubSystems();
}

SEAShell* SEAShellWapper::static_SEAShell_GetSEAShell(const QString& name)
{
    SEAShell* shell = new SEAShell(name);
    this->initShell(shell);
    return shell;
}

void SEAShellWapper::addPoint(SEAShell* obj, int pointId/*, int type*/)
{
    if (!obj)return;
    bool ok = obj->addPoint(pointId/*, type*/);
    if (!ok) {
        AppFrame::FITKMessageError("Add point failed !");
    }
}

void SEAShellWapper::createShell(SEAShell* obj, int type,int numRing)
{
    if (!obj)return;
    bool ok = false;
    if (type == 1) 
    {
        ok = obj->createPlate();
    }else if (type == 2) 
    {
        ok = obj->createSinglyCurvedShell();
    }else if (type == 3) 
    {
        ok = obj->createDoublyCurvedShell(numRing);
    }
    if (!ok) {
        AppFrame::FITKMessageError("Shell create failed !");
    }
    else
    {
        //渲染层显示数据
        EventOper::GraphEventOperator* graphOper = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("GraphPreprocess");
        if (graphOper == nullptr)return ;
        int objID = obj->getShellID();
        graphOper->updateGraph(objID, true);
    }
}

void SEAShellWapper::setDamping(SEAShell * obj, int type, const QString& damping)
{
    if (!obj)return;
    bool ok = obj->setDamping(type, damping);;
    if (!ok) {
        AppFrame::FITKMessageError("Set Damping failed !");
    }
}

void SEAShellWapper::closeDamping(SEAShell * obj)
{
    if (obj) obj->forbiddenDamping();
}

void SEAShellWapper::setNCT(SEAShell * obj, int NCT, double Covered, const QString& NCTtypeName)
{
    if (!obj)return;
    bool ok = ok = obj->setNCT(NCT, Covered, NCTtypeName);
    if (!ok) {
        AppFrame::FITKMessageError("Set Noise Control Treatments failed !");
    }
}

void SEAShellWapper::setPhysicalProp(SEAShell * obj, const QString & pro)
{
    if (!obj)return;
    bool ok = obj->setPhysicalProp(pro);
    if (!ok) {
        AppFrame::FITKMessageError("Set Physical Property failed !");
    }
}

QString SEAShellWapper::getName(SEAShell* obj)
{
    if (obj)
        return obj->getName();
    return QString();
}

void SEAShellWapper::setName(SEAShell* obj, const QString& name)
{
    if (!obj)return;
    bool ok = obj->setName(name);
    if (!ok) {
        AppFrame::FITKMessageError("Set Name failed !");
    }
}

void SEAShellWapper::setEffRadiationDimensions(SEAShell * obj, double area, double perimeter)
{
    if (!obj)return;
    bool ok = obj->setEffRadiationDimensions(area, perimeter);
    if (!ok) {
        AppFrame::FITKMessageError("Set Radiation Dimensions failed !");
    }
}

void SEAShellWapper::setSEAMatrixSolution_ModalDensity(SEAShell* obj, int type, bool isSolution, bool isModalDensity, const QString & modalDensity)
{
    if (!obj)return;
    bool ok = obj->setSEAMatrixSolution(type, isSolution);
    if (!ok) {
        AppFrame::FITKMessageError("Set SEA Matrix Solution failed !");
        return;
    }
    ok = obj->setModalDensity(type, isModalDensity, modalDensity);
    if (!ok) {
        AppFrame::FITKMessageError("Set SEA Matrix Solution succeed,Set Modal Density failed !");
    }
}

void SEAShellWapper::setFlexureCorrectionSDP(SEAShell * obj, bool is, double length, double width)
{
    if (!obj)return;
    bool ok = obj->setFlexureCorrectionSDP(is, length, width);
    if (!ok) {
        AppFrame::FITKMessageError("Set Correction for Sub-Divided Panels failed !");
    }
}

void SEAShellWapper::setDampingFromNCT(SEAShell * obj, bool is)
{
    if (!obj)return;
    bool ok = obj->setDampingFromNCT(is);
    if (!ok) {
        AppFrame::FITKMessageError("Set Damping From noise control treatment failed !");
        return;
    }
}

void SEAShellWapper::setDampingFromPhyProp(SEAShell * obj, bool is)
{
    if (!obj)return;
    bool ok = obj->setDampingFromPhyProp(is);
    if (!ok) {
        AppFrame::FITKMessageError("Set Damping From Physical Property failed !");
        return;
    }
}

QString SEAShellWapper::getGeometryProp(SEAShell * obj)
{
    if (obj)  return obj->getGeometryProp();
}

void SEAShellWapper::initShell(SEAShell* shell)
{
    if (shell == nullptr) return;
    Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
    if (phy == nullptr) return;
    
    Acoustics::FITKAcousticsMaterialManager* matMgr = phy->getMaterialManager();
    Acoustics::FITKAcousticsSpectraManager* specMgr = phy->getFITKAcousticsSpectraManager();
    Acoustics::FITKAcousticsNCTManager* nctMgr = phy->getFITKAcousticsNCTManager();
    Acoustics::FITKAcousticsPhysicsPropManager* propMgr = phy->getPhysicsPropManager();

    shell->setMaterialManager(matMgr);
    shell->setSpectraMgr(specMgr);
    shell->setNCTMgr(nctMgr);
    shell->setPropertyManager(propMgr);

}

SEAShell::SEAShell(const QString& name) :
    Acoustics::PyFITKSEAShell(name)
{

}
SEAShell::SEAShell() :
    Acoustics::PyFITKSEAShell()
{

}